import { reactive } from "vue";

export const newData = (oldData: any[], num: number, item: number) => {
    //表格用到的参数
    const state = reactive({
        page: num,
        //每页显示几条数据
        limit: item,
        total: oldData.length,
    });
    //前端限制分页（newData为当前展示页表格）
    const newData = () => {
        return oldData.filter(
            (item, index) =>
                //起始下标（从哪儿开始取）
                index < state.page * state.limit &&
                //终止下标（到哪儿结束）
                index >= state.limit * (state.page - 1)
        );
    };
    //改变页码
    const handleCurrentChange = (e: any) => {
        state.page = e;
        // console.log(e);
    };

    //改变页数限制
    const handleSizeChange = (e: any) => {
        state.limit = e;
        console.log(e);
    };

    console.log(newData());

    return newData()
}
